//
//  ModelLampControlView.m
//  宜居HD
//
//  Created by 张金国 on 16/4/28.
//  Copyright © 2016年 张金国. All rights reserved.
//

#import "ModelLampControlView.h"
#import "TitleView.h"
#import "BigButton.h"
#import "Masonry.h"
#import "UIButton+ColorandText.h"
#import "UIColor+RandomColor.h"
#import "Macro.h"

@implementation ModelLampControlView
#pragma mark - init
- (instancetype)initWithModelLampControlViewBlock:(ModelLampControlViewBlock)modelLampControlViewBlock {
    if (self = [super init]) {
        self.modelLampControlViewBlock = modelLampControlViewBlock;
        [self setupConstraints];
    }
    return self;
}
#pragma mark - private
- (void)setupConstraints {
    TitleView *titleView = [[TitleView  alloc]initWithLineColor:[UIColor redColor] title:@"模型灯光控制" titleFont:kLabelTextColor];
    [self addSubview:titleView];
    [titleView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.equalTo(self).offset(10);
        make.height.equalTo(self.mas_height).multipliedBy(1/4.0f);
        make.width.equalTo(self.mas_width).multipliedBy(1/4.0f);
    }];
    UIButton *tempbutton = nil;
    for (int i = 0; i < 8; i ++) {
        UIButton *button1 = [UIButton buttonWithBackgroundColor:[UIColor randomColor] textFont:[UIFont preferredFontForTextStyle:UIFontTextStyleTitle3] textColor:[UIColor whiteColor] title:@"宜居公园" cornerRadius:5.0f];
        button1.tag = i;
        [button1 addTarget:self action:@selector(handleButtonEvent:) forControlEvents:UIControlEventTouchUpInside];
        
        [self addSubview:button1];
        
        if (tempbutton == nil) {
            
            [button1 mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(titleView.mas_bottom);
                make.left.equalTo(titleView.mas_left);
                make.width.equalTo(self.mas_width).multipliedBy(1/10.0f);
                make.height.equalTo(self.mas_height).multipliedBy(1/5.0f);
            }];
        }else {
            
            [button1 mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(titleView.mas_bottom);
                make.left.equalTo(tempbutton.mas_right).offset(20);
                make.width.equalTo(self.mas_width).multipliedBy(1/10.0f);
                make.height.equalTo(self.mas_height).multipliedBy(1/5.0f);
            }];
        }
        tempbutton = button1;
        if (i == 0) {
            UIButton *button = [UIButton buttonWithBackgroundColor:[UIColor randomColor] textFont:[UIFont preferredFontForTextStyle:UIFontTextStyleTitle3] textColor:[UIColor whiteColor] title:@"宜居公园" cornerRadius:5.0f];
            button.tag = 8;
            [self  addSubview:button];
            [button addTarget:self action:@selector(handleButtonEvent:) forControlEvents:UIControlEventTouchUpInside];
            [button mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(button1.mas_bottom).offset(20);
                make.left.equalTo(button1.mas_left);
                make.width.equalTo(self.mas_width).multipliedBy(1/10.0f);
                make.height.equalTo(self.mas_height).multipliedBy(1/5.0f);
            }];
        }
        if (i == 1) {
            UIButton *button = [UIButton buttonWithBackgroundColor:[UIColor randomColor] textFont:[UIFont preferredFontForTextStyle:UIFontTextStyleTitle3] textColor:[UIColor whiteColor] title:@"宜居公园" cornerRadius:5.0f];
            button.tag = 9;
            [button addTarget:self action:@selector(handleButtonEvent:) forControlEvents:UIControlEventTouchUpInside];
            [self  addSubview:button];
            [button mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(button1.mas_bottom).offset(20);
                make.left.equalTo(button1.mas_left);
                make.width.equalTo(self.mas_width).multipliedBy(1/10.0f);
                make.height.equalTo(self.mas_height).multipliedBy(1/5.0f);
            }];
        }

    }
   
}

- (void)handleButtonEvent:(UIButton *)button {
    ModelLampControlButtonType modelLampControlButtonType = button.tag;
    self.modelLampControlViewBlock(modelLampControlButtonType);
}

@end
